#ifndef RESOURCE_HANDLER_H
#define RESOURCE_HANDLER_H

#include "capi/cef_resource_handler_capi.h"
#include "logger.h"

typedef struct _stream_resource_handler_t {
    cef_resource_handler_t handler;
    int status_code;
    cef_string_t status_text;
    cef_string_t mime_type;
    cef_string_multimap_t hearder_map;
    cef_stream_reader_t *stream;
} stream_resource_handler_t;

int CEF_CALLBACK process_request(
    struct _cef_resource_handler_t* self, 
    struct _cef_request_t* request, 
    struct _cef_callback_t* callback);

void CEF_CALLBACK get_response_headers(struct _cef_resource_handler_t* self,
    struct _cef_response_t* response,
    int64_t* response_length,
    cef_string_t* redirectUrl);
    
int CEF_CALLBACK skip(struct _cef_resource_handler_t* self,
                          int64_t bytes_to_skip,
                          int64_t* bytes_skipped,
                          struct _cef_resource_skip_callback_t* callback);

int CEF_CALLBACK read(struct _cef_resource_handler_t* self,
                          void* data_out,
                          int bytes_to_read,
                          int* bytes_read,
                          struct _cef_resource_read_callback_t* callback);

void CEF_CALLBACK cancel(struct _cef_resource_handler_t* self);

cef_resource_handler_t *create_stream_resource_handler(
    int status_code,
    const cef_string_t *status_text,
    const cef_string_t *mime_type,
    const cef_string_multimap_t hearder_map,
    cef_stream_reader_t *stream);

#endif